package com.vancouver.knows.ui.fragment.citynews;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.TextView;

import com.vancouver.knows.R;

/**
 * 相片编辑时弹出的操作选择弹窗 Created by cxlin.
 */
public class SelectPicWindow extends Dialog {

	private TextView btn_take_photo, btn_pick_photo, btn_cancel;
	private View mMenuView;

	public SelectPicWindow(Activity context, View.OnClickListener itemsOnClick) {
		super(context, R.style.SelectPicTheme);
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		mMenuView = inflater.inflate(R.layout.addpost_selector_layout, null);
		btn_take_photo = (TextView) mMenuView.findViewById(R.id.btn_take_photo);
		btn_pick_photo = (TextView) mMenuView.findViewById(R.id.btn_pick_photo);
		btn_cancel = (TextView) mMenuView.findViewById(R.id.btn_cancel);
		// 取消按钮
		btn_cancel.setOnClickListener(new View.OnClickListener() {

			public void onClick(View v) {
				// 销毁弹出框
				dismiss();
			}
		});
		// 设置按钮监听
		btn_pick_photo.setOnClickListener(itemsOnClick);
		btn_take_photo.setOnClickListener(itemsOnClick);
		WindowManager.LayoutParams windowAttributes = this.getWindow().getAttributes();
		windowAttributes.gravity = Gravity.BOTTOM;
		this.setCancelable(true);

		WindowManager windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
		DisplayMetrics metric = new DisplayMetrics();
		windowManager.getDefaultDisplay().getMetrics(metric);
		int width = metric.widthPixels;

		this.setContentView(mMenuView, new ViewGroup.LayoutParams(width, ViewGroup.LayoutParams.WRAP_CONTENT));
	}
}
